package com.example.demo.server3.affair;

import com.example.demo.server3.template.CMPP_SUBMIT;
import com.example.demo.server3.template.CMPP_SUBMIT_RESP;
import com.example.demo.server3.template.MessageHeader;
import com.example.demo.server3.template.ProtocolTemplate;
import com.example.demo.server3.tool.DemoByteUtil;

import java.time.LocalDateTime;

public class RealAffair {
    public static CMPP_SUBMIT_RESP submit(ProtocolTemplate protocolTemplate){
        CMPP_SUBMIT cmpp_submit = (CMPP_SUBMIT) protocolTemplate;
        //假装发送完消息了
        MessageHeader messageHeader = new MessageHeader(21,0x80000004,cmpp_submit.getMessageHeader().getSequence_Id());
        LocalDateTime localDateTime = LocalDateTime.now();

        StringBuffer sb = new StringBuffer();
        sb.append(DemoByteUtil.intToBinary(localDateTime.getMonth().getValue(),4));
        sb.append(DemoByteUtil.intToBinary(localDateTime.getDayOfMonth(),5));
        sb.append(DemoByteUtil.intToBinary(localDateTime.getHour(),5));
        sb.append(DemoByteUtil.intToBinary(localDateTime.getMinute(),6));
        sb.append(DemoByteUtil.intToBinary(localDateTime.getSecond(),5));
        sb.append(DemoByteUtil.leftComplement0("123123123",22));//这里随便写了个网关代码
        sb.append(DemoByteUtil.leftComplement0("1",16));//这个cmpp协议上写的顺序增加没搞明白
        CMPP_SUBMIT_RESP cmpp_submit_resp = new CMPP_SUBMIT_RESP(Long.parseLong(sb.toString()),(byte)0);
        cmpp_submit_resp.setMessageHeader(messageHeader);

        return cmpp_submit_resp;
    }
}
